#include "list.h"

static inline void clean_node(list_t *x)
{
    x->prev = NULL;
    x->next = NULL;
}

list_t *list_new(void *data)
{
    list_t *node = (list_t *)list_malloc(sizeof(list_t));
    if (node) {
        clean_node(node);
        node->data = data;
    }
    return node;
}

void list_del(list_t *node)
{
    if (node) {
        clean_node(node);
        node->data = NULL;
        list_free(node);
        node = NULL;
    }
}

inline void list_init(list_t *list)
{
    list->prev = list;
    list->next = list;
}

inline void list_insert(list_t *i, list_t *x)
{
	x->prev = i->prev;
	x->next = i;
	x->prev->next = x;
	x->next->prev = x;
}

void list_remove(list_t *x)
{
	x->prev->next = x->next;
	x->next->prev = x->prev;
}

inline void list_append(list_t *list, list_t *x)
{
	list_insert(list, x);
}

inline void list_prepend(list_t *list, list_t *x)
{
	list_insert(list->next, x);
}

